package com.starinside.wp.repository;

import com.starinside.wp.domain.observation.ObservationNewQuestionRecord;
import com.starinside.wp.domain.record.LiveRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * *******************************
 * Created by Tim.
 * form com.matt
 * on 2017/7/25
 * *******************************
 */
@Repository
public interface ObservationNewQuestionRecordRepository extends JpaRepository<ObservationNewQuestionRecord, String> {

    List<ObservationNewQuestionRecord> findAllByObservationRecordIdAndDeletedFalseOrderByScoreDesc(String observationRecordId);

    @Query(value = "select id, deleted, observationId, observationQuestion, observationRecordId, GROUP_CONCAT(`optionId` separator \"|\") as optionId, GROUP_CONCAT(`optionTitle` separator \"<br/>\" ) as optionTitle, resourceUrl, score " +
            "from observation_new_question_record  " +
            "where observationRecordId=?1 and deleted=0 " +
            "GROUP BY observationQuestion " +
            "order by `score` desc , `optionId`  asc", nativeQuery = true)
    List<ObservationNewQuestionRecord> findAllQuestionGroupedByTitle(String observationRecordId);

}
